package com.flitsneak.rocket.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
import org.springframework.messaging.Message;

/**
 * @author flitsneak
 * @email flitsneak@gmail.com
 * @date 2022/8/9 15:04
 * @description
 */
@Slf4j
@RocketMQTransactionListener
public class RocketTransactionalListener implements RocketMQLocalTransactionListener {
    @Override
    public RocketMQLocalTransactionState executeLocalTransaction(Message message, Object o) {
        log.info("执行本地事务");
        //执行本地事务
        return RocketMQLocalTransactionState.UNKNOWN;
    }

    /**
     * 事务补偿
     * @param message 元消息
     */
    @Override
    public RocketMQLocalTransactionState checkLocalTransaction(Message message) {
        log.info("检查本地事务");
        //检查消息的本地执行结果
        return RocketMQLocalTransactionState.COMMIT;
    }
}
